﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Serialization.Formatters;
using System.Text;
using System.Threading.Tasks;

namespace _011_1RemotingClientCallBack
{
    class MyCallback : MarshalByRefObject ,_011_1RemotingServerCallBack.ICallBack
    {

        public void OnCallBack(string message)
        {
            Console.WriteLine(message);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            MyCallback clb = new MyCallback();

            //*
            BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
            provider.TypeFilterLevel = TypeFilterLevel.Full;
            // Creating the IDictionary to set the port on the channel instance.
            IDictionary props = new Hashtable();
            props["port"] = 0;
            // Pass the properties for the port setting and the server provider in the server chain argument. (Client remains null here.)
            TcpChannel chan = new TcpChannel(props, null, provider);
            //*/
            //TcpChannel chan = new TcpChannel();


            ChannelServices.RegisterChannel(chan, true);
            _011_1RemotingServerCallBack.IServer srv = (_011_1RemotingServerCallBack.IServer)Activator.GetObject(typeof(_011_1RemotingServerCallBack.Server), "tcp://localhost:25701/Server");
            srv.Action(clb);
            Console.ReadLine();

        }
    }
}
